package com.ytc.search.controller;

import com.ytc.commons.model.dto.CoursePubIndexDto;
import com.ytc.commons.model.dto.PageRequest;
import com.ytc.commons.model.vo.CoursePubIndexVo;
import com.ytc.commons.model.vo.PageResponseResult;
import com.ytc.commons.model.vo.ResponseResult;
import com.ytc.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class SearchController {

    @Autowired
    private SearchService searchService;
    /*
     * 条件查询
     * 请求地址：POST /course-search
     * 请求参数分页查询：
     * Body：CoursePubIndexDto
     * Query: PageRequest
     * 响应：PageResponseResult<CoursePubIndexVo>
     * */
    @PostMapping("/course-search")
    public PageResponseResult<CoursePubIndexVo> search(
            @RequestBody CoursePubIndexDto dto,
            PageRequest request
            )throws Exception{
        return searchService.search(dto,request);

    }

    /*
    * //根据id查询课程发布数据
    * 地址：GET /course-search/{id}
    * 返回值： ResponseResult<CoursePubIndexVo>
    *
    * */
   @GetMapping("/course-search/{id}")
    public ResponseResult<CoursePubIndexVo> findById(@PathVariable("id") Long id)throws Exception{
        return searchService.findById(id);
    }
}
